
//
//  LinkedList_disordered.swift
//  SwiftyDSA
//
//  Created by Archer on 2018/8/9.
//  Copyright © 2018年 Archer. All rights reserved.
//

import Foundation

extension LinkedList where Element: Comparable {
    
    /// 逆序对数目
    public func disordered() -> Int {
        if count < 2 { return 0 }
        var cnt = 0
        var nd = first
        while nd?.successor !== _trailer {
            cnt += (nd! > (nd?.successor)!).toInt()
            nd = nd?.successor
        }
        return cnt
    }
}
